package com.heima.cart.listener;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.heima.cart.domain.po.Cart;
import com.heima.cart.service.ICartService;
import com.hmall.common.utils.UserContext;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author gonghuaiguo
 */
@Component
public class TradeCreateListener {

    @Autowired
    ICartService cartService;

    //@RabbitListener(bindings = @QueueBinding(
    //        value = @Queue(name = "cart.clear.queue",durable = "true"),
    //        exchange = @Exchange(name = "trade.topic"),
    //        key = "order.create"
    //) )
    public void listenerTradeCreateSuccess(Message message, Set<Long> itemIds){
        // 获取用户登录信息
        Long userId = message.getMessageProperties().getHeader("user-info");
        UserContext.setUser(userId);
        // 删除
        cartService.removeByItemIds(itemIds);
    }
}
